package com.ruoyi.web.controller.carbon;


import com.ruoyi.carbon.domain.CheliangDiaodu;
import com.ruoyi.carbon.domain.dto.CheliangDiaoduDto;
import com.ruoyi.carbon.domain.vo.CheliangDiaoduVo;
import com.ruoyi.carbon.service.CheliangDiaoduService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RestController
@RequestMapping("/carbon/cheliangDiaodu")
@Valid
@Anonymous
public class CheliangDiaoduController extends BaseController {

    @Autowired
    private CheliangDiaoduService cheliangDiaoduService;


    @GetMapping("/list")
    public TableDataInfo list(CheliangDiaodu cheliangDiaodu) {
        startPage();
        List<CheliangDiaodu> list = cheliangDiaoduService.getList(cheliangDiaodu);
        return getDataTable(list);
    }

    @PostMapping
    public AjaxResult save(@Validated @RequestBody CheliangDiaoduVo cheliangDiaoduVo) {

        return toAjax(cheliangDiaoduService.save(cheliangDiaoduVo));
    }

    @GetMapping("/{id}")
    public AjaxResult getAllInfoById(@PathVariable Long id) {
        return success(cheliangDiaoduService.getAllInfoById(id));
    }

    @PutMapping
    private AjaxResult edit(@RequestBody CheliangDiaoduVo cheliangDiaoduVo) {
        int result = cheliangDiaoduService.update(cheliangDiaoduVo);
        return result ==  0 ? error() : success();
    }
}
